package chapter12;

import java.util.*;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/20 13:48
 */
public class CollectionsTest {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(Arrays.asList(35, 24, 13, 12, 8, 7, 1));
        System.out.println(Collections.binarySearch(list, 7, Collections.reverseOrder()));

        System.out.println(Collections.frequency(list, 1));

        List<Integer> list1 = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));

        System.out.println("disjoint?" + Collections.disjoint(list1, list));

        System.out.println("list befor sort:" + list);
        Collections.sort(list);
        System.out.println("list after sort:" + list);

        Collections.reverse(list);
        System.out.println("list after reverse:" + list);

        Collections.shuffle(list);
        System.out.println("list after shuffle:" + list);

        List<Integer> list2 = new ArrayList<>(Arrays.asList(8, 5, 3, 6, 2));
        Collections.rotate(list2, 2);
        System.out.println((list2));

        list2 = new ArrayList<>(Arrays.asList(8, 5, 3, 6, 2));
        Collections.rotate(list2, -2);
        System.out.println(list2);

        List<Integer> list3 = new ArrayList<>(Arrays.asList(8, 5, 3, 6, 2, 19, 21));
        Collections.rotate(list.subList(1, 5), 2);
        System.out.println(list3);

        List<String> stringList = new ArrayList<>();
        String[] array = new String[]{"深入", "浅出"};
        Collections.addAll(stringList, array);
        Collections.addAll(stringList, "hell", "world", "老马", "编程");
        System.out.println(stringList);

        List<String> stringList1 = Collections.emptyList();
        Map<String, Integer> map = Collections.emptyMap();
        Set<Integer> set = Collections.emptySet();

        List<String> stringList2 = Collections.EMPTY_LIST;

        Collection<String> collection = Collections.singleton("编程");
        Set<String> set0 = Collections.singleton("编程");
        List<String> list0 = Collections.singletonList("老马");
        Map<String, String> map0 = Collections.singletonMap("老马", "编程");

        System.out.println("singleton list:" + list0);

        List<String> oList = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "b"));
        Collections.addAll(oList, "e", "b", "c");
        System.out.println("before remove:" + oList);
        oList.remove("b");
        System.out.println("after remove" + oList);

        oList.removeAll(Collections.singletonList("b"));
        System.out.println("after removeAll" + oList);


    }
}
